package br.edu.senai.controller;

import br.edu.senai.model.Medicao;
import java.util.List;
import javax.persistence.Query;

/**
 * @author william.chenta
 */
public class MedicaoDAOP {

    private final Conexao conexao = new Conexao();

    public void salvar(Medicao m) {
        if (m.getId() == null) {
            conexao.persist(m);
        } else {
            conexao.alterar(m);
        }
    }

    public void remover(Medicao m) {
        conexao.excluir(m);
    }

    public List<Medicao> listar() {
        conexao.conectar();
        Query q = conexao.getEm().createQuery("select m from tb_medicao m");
        List<Medicao> lMedicao = q.getResultList();
        conexao.desconectar();
        return lMedicao;
    }

    public Medicao find(Long id) {
        conexao.conectar();
        Medicao m = conexao.getEm().find(Medicao.class, id);
        conexao.desconectar();
        return m;
    }
}
